package cn.tedu.wms.passport.controller;

import cn.tedu.wms.passport.pojo.dto.PermissionAddNewDTO;

import cn.tedu.wms.passport.pojo.vo.PermissionListVO;
import cn.tedu.wms.passport.pojo.vo.PermissionStandardVO;
import cn.tedu.wms.passport.service.IPermissionService;
import cn.tedu.wms.passport.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Api(tags = "05. 权限管理模块")
@RequestMapping("/permissions")
public class PermissionController {

    @Autowired
    IPermissionService permissionService;

    public PermissionController() {
        log.info("创建控制器对象: PermissionController");
    }

    @PostMapping("/add")
    @ApiOperation(value = "添加权限")
    @ApiOperationSupport(order = 100)
    public JsonResult<Void> addNew(PermissionAddNewDTO permissionAddNewDTO){
        log.debug("即将开始处理添加权限请求,参数: {}",permissionAddNewDTO);
        permissionService.add(permissionAddNewDTO);
        return JsonResult.ok();
    }

    @PostMapping("/{id:[0-9]+}/delete")
    @ApiOperation(value = "删除权限")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name = "id", value = "权限id", required = true, dataType = "long")
    public JsonResult<Void> deleteById(@PathVariable Long id){
        log.debug("即将开始处理删除权限请求,参数: {}",id);
        permissionService.deleteById(id);
        return JsonResult.ok();
    }

    @GetMapping("/{id:[0-9]+}")
    @ApiOperation(value = "根据id查询权限详情")
    @ApiOperationSupport(order = 400)
    @ApiImplicitParam(name = "id", value = "权限id", required = true, dataType = "long")
    public JsonResult<PermissionStandardVO> getById(@PathVariable Long id){
        log.debug("即将开始处理查询权限详情请求,参数: {}",id);
        PermissionStandardVO permissionStandardVO = permissionService.getById(id);
        return JsonResult.ok(permissionStandardVO);
    }

    @GetMapping("")
    @ApiOperation(value = "查询权限列表")
    @ApiOperationSupport(order = 410)
    public JsonResult<List<PermissionListVO>> list(){
        log.debug("即将开始处理查询权限列表请求");
        List<PermissionListVO> list=permissionService.list();
        return JsonResult.ok(list);
    }
}
